Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to persist theme selection #941

Merged

Conversation

YoussefHenna
Copy link
Collaborator

@YoussefHenna YoussefHenna commented Aug 25, 2024

  • When we eventually add themes to draftbit and an action to change the theme, we should also have a way to persist that selection so that the theme does not reset every time an app is relaunched.

🚀 This description was created by Ellipsis for commit fa62274

Summary:

This PR adds theme persistence using AsyncStorage and updates jest setup files to mock AsyncStorage for testing.

Key points:

  • Adds theme persistence using AsyncStorage in the Provider component.
  • Updates jest setup files to mock AsyncStorage for testing.
  • Adds @react-native-async-storage/async-storage to dependencies.
  • Persists theme selection using AsyncStorage in Provider.tsx.
  • Introduces SAVED_SELECTED_THEME_KEY constant for storage key.
  • Modifies changeTheme function to accept ChangeThemeOptions.
  • Adds React.useEffect to load persisted theme on initialization.
  • Updates useChangeTheme hook to support ChangeThemeOptions.

Generated with ❤️ by ellipsis.dev

Copy link

linear bot commented Aug 25, 2024

Copy link

Published version: @draftbit/ui@49.6.8-f99c50.2

Copy link
Contributor

@adnelson adnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

});

React.useEffect(() => {
const run = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider if the UI shakes slightly during initialization due to the absence of a wait state when loading the theme.

👉 Example: the UI may briefly display with theme1 before switching to theme2, causing a flicker.

If thorough testing shows no issue, you can disregard this comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since storage is async, the only way to fix an eventual flicker would be to render nothing and wait on the storage to give back data. Let see if the current approach is working and fix it if it causes flickers!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about the same thing, but saw no flicker during testing. We can always come back to it and fix if the issue does arise at some point.

Copy link
Contributor

@needs needs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

});

React.useEffect(() => {
const run = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since storage is async, the only way to fix an eventual flicker would be to render nothing and wait on the storage to give back data. Let see if the current approach is working and fix it if it causes flickers!

@YoussefHenna YoussefHenna merged commit 3f266c0 into master Aug 26, 2024
3 checks passed
@YoussefHenna YoussefHenna deleted the youssef/p-5355-add-a-way-to-persist-theme-selection branch August 26, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants